package rules.feedback;

import rules.Rule;
import systemconfig.SystemConfiguration;
import exceptions.CommentTooLongException;
import exceptions.CommentTooShortException;
import feedback.FeedbackComment;
import feedback.PersonFeedback;

/**
 * A rule validating the comment string length.
 */
public class CommentLenghtRule implements Rule<PersonFeedback> {

    @Override
    public void validate(final PersonFeedback feedback) {
        SystemConfiguration syscfg = SystemConfiguration.getInstance();
        FeedbackComment comment = feedback.getComment();
        if (comment.getNegative().length() > syscfg.getMaximumCommentLength()
                || comment.getPositive().length() > syscfg.getMaximumCommentLength()) {

            throw new CommentTooLongException();
        }
        if (comment.getNegative().length() < syscfg.getMinimumCommentLength()
                || comment.getPositive().length() < syscfg.getMinimumCommentLength()) {
            throw new CommentTooShortException();
        }

    }

}
